<template>
	<view class="topComSty">

		<view>
			<view class="box-bg">
			</view>
			<view class="nav_wrap">
				<!-- <view class=" iconfont icon-shouye-shouye" style="color:white;font-size: 32upx;">
				</view> -->
				<view class="topIndexFlex">
					<view class="iconfont icon-shouye-shouye"
						style="font-size: 38rpx;margin-right:50rpx;margin-left: 60rpx;" v-if="topName=='首页'"></view>
					{{topName}}
				</view>
				
				<view @click="skipFun()" style="font-size: 28rpx; margin-right: 560rpx;">
					<span>{{userName}}</span>
					<span class="iconfont icon-xiajiantou" style="font-size: 28rpx;"></span>
				</view>
				
                 <view class="topSty" v-if="isShow">
					<view class="navList" v-for="(item,index) in roleList" :key="index" @click="skipClassFun(item)">
						{{item.classDeptName}}
					</view>
					
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import index from "@/api/modules/index.js"
	export default {
		name: "topCom",
		props: {
			userName: String,
			topName: String,
			buildingNo: String,
			classDeptId: String,
			type: String,
			url: String
		},
		data() {
			return {
				buildFont: '畔湖苑',
				roleName: '',
				classId: '',
				roleList: [],
				navList: [{
					title: "启蒙星",
					path: ""
				}, {
					title: "BCSP",
					path: ""
				}, {
					title: "实训",
					path: ""
				}, {
					title: "课工场",
					path: ""
				}, ],
				buildNoList: [{
						classDeptName: "畔湖苑",
						path: "1"
					}, {
						classDeptName: "明志楼",
						path: "2"
					},
					{
						classDeptName: "听湖苑",
						path: "2"
					}, {
						classDeptName: "退出",
						path: "2"
					}
				],
				isShow: false,
				titleFont: '',
				isDuty: 0,
				platform: "",

			}
		},
		methods: {
			logout() {
				console.log("退出用户！！！！！！！！！！！！！！！！！！！！！！！！！！！！")
				uni.showModal({
					content: '确认退出?',
					title: '提示',
					success: (res) => {
						if (res.confirm) {
							index.logout()
							uni.clearStorageSync()
							uni.reLaunch({
								url: '/pages/index/login'
							})
							return;
						}
					}
				})
			},
			skipFun() {
				// console.log("111")
				// console.log(uni.getStorageSync("userInfo"))
                this.isShow = !this.isShow
				

			},
			skipClassFun(item) {
				console.log("222")
				this.userRole = item.classDeptName
				console.log(this.userRole)
				uni.setStorageSync("userRole", item.classDeptName)
				if (item.classDeptName == '退出') {
					index.logout()
					uni.clearStorageSync()
					uni.reLaunch({
						url: '/pages/index/login'
					})
					return;
				}
				if (item.classDeptName == '班主任') {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				} else if (item.classDeptName == '部门经理') {
					uni.reLaunch({
						url: '/pages/classManagement/classManagementIndex?userRole=${item.classDeptName}'
					})
				} else if (item.classDeptName == '维修管理员') {
					uni.reLaunch({
						url: '/pages/maintenance/maintenanceIndex'
					})
				} else if (item.classDeptName == '宿管老师' || item.classDeptName == '超级管理员') {
					uni.reLaunch({
						url: "/pages/index/supervisorIndex",
						// url: "/pages/classManagement/classManagementDormitoryAttendance?buildingNo=畔湖苑&type=考勤",
					})
				} else if (item.classDeptName == '教官') {
					uni.reLaunch({
						url: "/pages/instructor/instructorIndex"
					})
					
					
				} 
				
			},
			getBack() {
				var userName = uni.getStorageSync("userName");
				if (this.url != undefined && userName != '战鹰') {
					// alert(this.url) 
					uni.navigateTo({
						url: this.url
					})
				} else {
					let canNavBack = getCurrentPages();
					if (canNavBack && canNavBack.length > 1) {
						uni.navigateBack({
							delta: 1
						});
					} else {
						history.back();
					}
				}

			},
			classDep() {
				this.$api.classManage.getAppClassDept().then(res => {
					this.navList = res.data
					this.navList.forEach((item, index) => {
						if (item.classDeptValue == this.classId) {
							this.titleFont = item.classDeptName
						}
					})
				})
			},
			// build() {
			// 	this.roleList.forEach((item) => {
			// 		if(item.classDeptName == this.userRole) {
			// 			this.userName = item.classDeptName
			// 		}
					
			// 	})
			// 	// this.navList.forEach((item) => {
			// 	// 	if (item.classDeptName == this.buildingNo) {
			// 	// 		this.buildFont = item.classDeptName
			// 	// 	}
			// 	// })
			// },


		},
		created() {
			console.log("top-view-created")
			
			var that = this
			that.classId = that.classDeptId
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route //获取当前页面路由
			let curParam = routes[routes.length - 1].options; //获取路由参数
			this.roleName = uni.getStorageSync("userInfo");
			// uni.getStorage({
			// 	key: "userInfo",
			// 	success: function(res) {
			// 		console.log(res.data)
			// 		this.roleName = res.data
			// 	},
			// 	fail: (res) => {}
			// })
			
			// console.log(this.roleName + 6666)
			
			// console.log(this.userName,this.$props,"userName")
			// uni.getStorage({
			// 	key:"loginName",
			// 	success:function(res){
			// 		that.userName = res.data

			// 	},
			// 	fail:(res)=>{

			// 	}  
			// })
			// console.log(that.roleName,that.userName,"roleName222")
			// debugger
			var roleList = [];
			if(that.roleName.search(",") != -1) {
				// 有几个角色
				var roleNames = that.roleName.split(",");
				
     			// classDeptName: "畔湖苑",
				//		path: "1"
				for(let i = 0; i < roleNames.length; i++) {
					let role = {classDeptName: roleNames[i], path: i}
					roleList.push(role);
				}
				
				let role = {classDeptName: "退出", path: roleNames.length + 1}
				roleList.push(role)
			} else {
				let role = {classDeptName: that.roleName, path: 0}
				roleList.push(role);
				let role1 = {classDeptName: "退出", path: 1}
				roleList.push(role1)
			}
			
			
			this.roleList = roleList;
			console.log(this.roleList)
			
			// this.build();
			// if (this.classId) {
			// 	this.classDep()
			// 	// this.buildingNo = null
			// } else {
			// 	this.navList = this.buildNoList
			// 	this.build()
			// }
		},
		onLoad() {
			console.log("top-view-onload")
		},
	}
</script>

<style>
	.box-bg {
		background-color: #0100cc;
		padding: 60rpx 0;
	}

	.topSty {
		background-color: #0000EE;
		width: 155rpx;
		/* height:190rpx; */
		position: absolute;
		top: 200rpx;
		left: 20rpx;
		z-index: 999999 !important;
		border-radius: 10rpx;
		text-align: center;
	}

	.navList {
		color: white;
		width: 150rpx;
		height: 45rpx;
		font-size: 32rpx;
		line-height: 30rpx;
		margin-top: 3rpx;
		/* padding-left:13rpx; */
		padding-top: 5rpx;
	}

	.topIndexFlex {
		font-weight: 800;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: -90upx;
		font-size: 42rpx;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		top: 228rpx;
	}

	.nav_wrap {
		width: 750upx;
		height: 125upx;
		text-align: center;
		color: #fff;
		font-size: 36upx;
		/*  #ifndef  MP-WEIXIN */
		margin-top: 60rpx;
		/*  #endif  */
		display: flex;
		justify-content: space-around;
		font-size: 38rpx;

	}

	.topNavFont {
		position: fixed;
		top: 100upx;
		right: 26upx;
		z-index: 999;
		color: white;
		font-size: 42rpx;
	}

	.topComSty {
		width: 100%;
		height: 300rpx;
		background-image: url(https://tj-1305380059.cos.ap-nanjing.myqcloud.com/pic/t-1.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		background-color: blue;
	}
</style>